import { createApp } from 'vue'
import App from './App.vue'
import { createPinia } from "pinia";
import { useStorage } from "@vueuse/core";

// 引入模板的全局的样式，其中包含了element组件的scss变量的修改，需要放到elementPlus之前
// elementPlus组件中文化
import ElementPlus from "element-plus";
import zhCn from "element-plus/dist/locale/zh-cn.mjs";

import 'element-plus/theme-chalk/el-message.css'
import 'element-plus/theme-chalk/el-message-box.css'
// import '~/styles/messageReset.scss'

import '~/styles/reset.scss'


// 引入路由
import router from '~/utils/router/vue-router.js'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'


const app = createApp(App);
app.use(ElementPlus, {
    locale: zhCn,
});
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
  }
const pinia = createPinia();
window.addEventListener("message", (event) => {
  console.log(event);
  // if (event.origin !== "http://172.16.50.80:8888") return;
  // 处理扩展程序的请求
  if (event.data.type === "GET_LOCALSTORAGE") {
    const payload = event.data.payload;
    let obj = {};
    payload.forEach((item) => {
      const value = sessionStorage.getItem(item.key);
      if (value) obj[item.key] = value;
    });
    // 返回数据给扩展程序
    event.source.postMessage(
      {
        type: "LOCALSTORAGE_RESPONSE",
        payload: obj,
      },
      event.origin
    );
  }
});
app.use(router);
app.use(pinia);
app.mount('#app')
